package net.zjitc.controller;

import net.zjitc.aop.Pager;
import net.zjitc.context.LocalThreadHolder;
import net.zjitc.pojo.api.Result;
import net.zjitc.pojo.dto.query.extend.BookSaveQueryDto;
import net.zjitc.pojo.entity.BookSave;
import net.zjitc.pojo.vo.BookSaveVO;
import net.zjitc.service.BookSaveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//书架收藏
@RestController
@RequestMapping(value = "/bookSave")
public class BookSaveController {

    @Resource
    private BookSaveService bookSaveService;

    //书架收藏新增
    @PostMapping(value = "/save")
    public Result<Void> save(@RequestBody BookSave bookSave) {
        return bookSaveService.save(bookSave);
    }

    //删除
    @PostMapping(value = "/batchDelete")
    public Result<Void> batchDelete(@RequestBody List<Integer> ids) {
        return bookSaveService.batchDelete(ids);
    }

    //修改
    @PutMapping(value = "/update")
    public Result<Void> update(@RequestBody BookSave bookSave) {
        return bookSaveService.update(bookSave);
    }

    //书架收藏用户查询
    @Pager
    @PostMapping(value = "/queryUser")
    public Result<List<BookSaveVO>> queryUser(@RequestBody BookSaveQueryDto bookSaveQueryDto) {
        bookSaveQueryDto.setUserId(LocalThreadHolder.getUserId());
        return bookSaveService.query(bookSaveQueryDto);
    }

    //书架收藏查询
    @Pager
    @PostMapping(value = "/query")
    public Result<List<BookSaveVO>> query(@RequestBody BookSaveQueryDto bookSaveQueryDto) {
        return bookSaveService.query(bookSaveQueryDto);
    }

}
